package main

import (
	"jinquan.supor.com/common"
	"jinquan.supor.com/samples/mongo/docs"
	"strings";"fmt"
)

func main() {
	//Pod 内部域名
	/*
	clnt, _ := common.Mongo_ServerConn(`mongodb://mongo-0.mongo.mongo-ns.svc.cluster.local:27017,
											      mongo-1.mongo.mongo-ns.svc.cluster.local:27017,
												  mongo-2.mongo.mongo-ns.svc.cluster.local:27017/?slaveOk=true`, 
												  "secondary")
	*/
	clnt, _ := common.Mongo_ServerConn(`mongodb://mongodb.jinquan.svc.cluster.local:27017`, "primary")
	
	var docArr = testdoc.GenDocArray(1)
	k1 := "Email";v1 := common.IfVal_string(docArr[0], k1)
	k2 := "Username";v2 := common.IfVal_string(docArr[0], k2)
	fmt.Printf("Original Data ->> %v\n", docArr[0])
	common.Mongo_CollAddDoc(clnt, "db_4", "coll_1", docArr[0])

	/* 获取返回Document的某个字段数据 */
	var docSt_X = testdoc.AllocDoc()
	fmt.Printf("docSt_X ->> %v\n", docSt_X[0])
	docSt_X[0], _ = common.Mongo_GetDoc(clnt , "db_4", "coll_1", 
							k1,v1, 
							k2,v2, 
							docSt_X[0])

	m := common.If2Map(docSt_X[0])	
	k := strings.ToLower("Email") //从MongoDB取出来的Key都是小写
	fmt.Printf("Get Document data ->> %s: %s\n", k, m[k])
}